﻿/*
 * 由SharpDevelop创建。
 * 用户： Joy
 * 日期: 2013/10/24
 * 时间: 23:03
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;

namespace FindDepth
{
    class Program
    {
        public static void Main(string[] args)
        {
            Forest.TreeNode[] nodes = new Forest.TreeNode[]{
                new Forest.TreeNode(){
                    Name = 0,
                    Parent = 0,
                    Weight = 0
                },
                new Forest.TreeNode(){
                    Name = 1,
                    Parent = 2,
                    Weight = 1
                },
                new Forest.TreeNode(){
                    Name = 2,
                    Parent = 2,
                    Weight = 7
                },
                new Forest.TreeNode(){
                    Name = 3,
                    Parent = 2,
                    Weight = -1
                },
                new Forest.TreeNode(){
                    Name = 4,
                    Parent = 5,
                    Weight = 1
                },
                new Forest.TreeNode(){
                    Name = 5,
                    Parent = 2,
                    Weight = -3
                },
                new Forest.TreeNode(){
                    Name = 6,
                    Parent = 7,
                    Weight = 1
                },
                new Forest.TreeNode(){
                    Name = 7,
                    Parent = 9,
                    Weight = 2
                },
                new Forest.TreeNode(){
                    Name = 8,
                    Parent = 9,
                    Weight = 1
                },
                new Forest.TreeNode(){
                    Name = 9,
                    Parent = 2,
                    Weight = -7
                }
            };
            Forest f = new Forest(10);
            f.Link(2, 1);
            output(f);
            f.Link(3, 2);
            output(f);
            f.Link(5, 4);
            output(f);
            f.Link(4, 3);
            output(f);
            f.Link(7, 6);
            output(f);
            f.Link(9, 8);
            output(f);
            f.Link(8, 7);
            output(f);
            f.FindDepth(6);
            output(f);
            f.Link(6, 5);
            output(f);
            f.FindDepth(4);
            output(f);
            f.FindDepth(7);
            output(f);
            Console.ReadKey(true);
        }
        private static void run1()
        {
 
        }
        private static void output(Forest f)
        {
            Console.WriteLine("Node\tParent\tWeight\tCount");
            for (int i = 1; i <= 9; i++)
            {
                Console.WriteLine(String.Format("{0}\t{1}\t{2}\t{3}",
                    f.nodes[i].Name, f.nodes[i].Parent, f.nodes[i].Weight, f.nodes[i].Count));
            }
            Console.WriteLine();
            Console.WriteLine();
        }
    }
}